import request from "@/utils/request.js";


// 提供调用注册接口的函数
export const userRegisterService = (registerData) => {
    // 直接传入会是 json 格式
    // URLSearchParams 将 json 格式转为 x-www-form-urlencoded 格式
    const params = new URLSearchParams();
    for (let registerDataKey in registerData) {
        params.append(registerDataKey, registerData[registerDataKey])
    }
    return request.post('/user/register', params)
}
export const userLoginAPI = (loginData) => {
    return request.post('/api/admin/login', loginData)
}
export const userInfoService = () => {
    return request.get('/user/userInfo')
}
export const userInfoUpdateService = (userInfoData) => {
    return request.put('/user/update', userInfoData)
}
export const userAvatarUpdateService = (avatarUrl) => {
    const params = new URLSearchParams()
    params.append('avatarUrl', avatarUrl)
    return request.patch('/user/updateAvatar', params)
}
export const getLoginCaptchaAPI = () => request.get('/res/captcha')
export const getUserListAPI = (page, limit) => {
    console.log(page, limit)
    return request.get('/api/user', {params: {page, limit}})
}
export const addUserAPI = (userInfo) => {
    return request.post('/api/user', userInfo)
}
export const getUserInfoByIdAPI = (id) => {
    return request.get('/api/user/' + id)
}
export const getCurrentUserInfoAPI = () => {
    return request.get('/api/admin/whoami')
}
export const userInfoUpdateAPI = (userInfo) => {
    return request.put('/api/admin', userInfo)
}